#!/usr/bin/python
#-*- coding: latin1 -*-
# @author herberthudson@gmail.com
# @version 1.0 - 6 Março de 2013
# @license Apache 2

import os, sys

def main(argv):

	index = int(sys.argv[1])
	device = getDevice(index)
	if(device):
		value = getUsage(device)
		print int(value)
	else:
		print 0

def getDevice(index):
	devices = os.listdir('/media')
	try:
		dev = devices[index]
		dev = dev.replace(' ', '\ ')
		device = '/media/' + dev
	except:
		return 0

	return device

def getUsage(dev):
	com="df -h " + dev + " | awk '{print $5}' | sed 's/Disp./\ /g' | sed 's/%/\ /g'"

	temp=os.popen(com)
	porcent=temp.read()
	return porcent

if __name__ == "__main__":
  	main(sys.argv)
